package com.HMI;

import java.awt.Font;
import java.util.Date;
import javax.swing.SwingConstants;
import com.Resources.CustomColor;

@SuppressWarnings("serial")
public class MainWindow extends AlphaPanel {

	// Summary Panels
	private AlphaPanel chlorinePanel;
	private AlphaPanel phPanel;
	private AlphaPanel schedulingPanel;
	
	// Panel Variables
	private PanelText lblChlorineLevelPPM;
	private PanelText lblPhLevelPh;
	private PanelText lblCurrentPressure;
	private PanelText lblCurrentChlorineTankStatus;
	private PanelText nextShockDay;
	private PanelText nextShockTime;
	
	public MainWindow(int x, int y, int width, int height) {
		super(x, y, width, height);
		this.setBackground(CustomColor.TRANSPARENT);
		initializeChlorinePanel();
		initializePhPanel();
		initializeSchedulePanel();
	}
	
	private void initializeChlorinePanel() {
		chlorinePanel = new AlphaPanel(40, 40, 502, 118);
		populateChlorinePanel();
		this.add(chlorinePanel);
	}

	private void populateChlorinePanel() {
		labelChlorineLevel();
		chlorineLevelPPM();
		labelTankStatus();
		chlorineTankStatus();
	}

	private void labelChlorineLevel() {
		PanelText lblChlorineLevel = new PanelText("Chlorine level:", 22, 29,
				215, 29, SwingConstants.LEFT, SwingConstants.BOTTOM);
		chlorinePanel.add(lblChlorineLevel);
	}

	private void chlorineLevelPPM() {
		lblChlorineLevelPPM = new PanelText("2.1 ppm", 305, 32, 175, 27,
				SwingConstants.RIGHT, SwingConstants.BOTTOM);
		chlorinePanel.add(lblChlorineLevelPPM);
	}
	
	public void setChlorineLevel(float level) {
		lblChlorineLevelPPM.setText("" + level + " ppm");
	}

	private void labelTankStatus() {
		PanelText lblTankStatus = new PanelText("Cl remaining:", 22, 64, 215,
				29, SwingConstants.LEFT, SwingConstants.BOTTOM);
		chlorinePanel.add(lblTankStatus);
	}

	private void chlorineTankStatus() {
		lblCurrentChlorineTankStatus = new PanelText("sufficient", 305, 64,
				175, 27, SwingConstants.RIGHT, SwingConstants.BOTTOM);
		chlorinePanel.add(lblCurrentChlorineTankStatus);
	}
	
	public void setChlorineTankStatus(String status) {
		lblCurrentChlorineTankStatus.setText(status);
	}
	
	private void initializePhPanel(){
		phPanel = new AlphaPanel(40, 187, 502, 118);
		populatePhPanel();
		this.add(phPanel);
	}
	
	private void populatePhPanel() {
		labelPhLevel();
		pHLevelpH();
//		labelPressure();
//		cO2Pressure();
	}
	
	private void labelPhLevel() {
		PanelText lblPhLevel = new PanelText("pH level:", 22, 29, 215, 29,
				SwingConstants.LEFT, SwingConstants.BOTTOM);
		phPanel.add(lblPhLevel);
	}
	
	private void pHLevelpH() {
		lblPhLevelPh = new PanelText("7.50", 305, 32, 175, 27,
				SwingConstants.RIGHT, SwingConstants.BOTTOM);
		phPanel.add(lblPhLevelPh);
	}
	
	public void setPhLevel(float level) {
		lblPhLevelPh.setText("" + level);
	}
	
	private void labelPressure() {
		PanelText lblTankPressure = new PanelText("CO2 remaining:", 22, 64, 215,
				29, SwingConstants.LEFT, SwingConstants.BOTTOM);
		phPanel.add(lblTankPressure);
	}
	
	private void cO2Pressure() {
		lblCurrentPressure = new PanelText("-", 305, 64, 175, 27,
				SwingConstants.RIGHT, SwingConstants.BOTTOM);
		phPanel.add(lblCurrentPressure);
	}

	public void setCO2Pressure(int pressure) {
		lblPhLevelPh.setText("" + pressure + " psi");
	}
	
	private void initializeSchedulePanel(){
		schedulingPanel = new AlphaPanel(40, 334, 502, 118);
		populateSchedulingPanel();
		this.add(schedulingPanel);
	}
	
	private void populateSchedulingPanel() {
		labelNextShock();
		shockDate();
		shockTime();
	}
	
	private void labelNextShock() {
		PanelText lblChlorineLevel = new PanelText("Next shock", 22, 29, 215,
				29, SwingConstants.LEFT, SwingConstants.BOTTOM);
		schedulingPanel.add(lblChlorineLevel);
	}
	
	private void shockDate() {
		nextShockDay = new PanelText("Sat, Mar 15", 305, 32, 175, 27,
				SwingConstants.RIGHT, SwingConstants.BOTTOM);
		schedulingPanel.add(nextShockDay);
	}
	
	private void shockTime() {
		nextShockTime = new PanelText("12:30 AM", 305, 65, 175, 27,
				SwingConstants.RIGHT, SwingConstants.BOTTOM);
		nextShockTime.setFont(new Font("DejaVu Sans", Font.PLAIN, 26));
		schedulingPanel.add(nextShockTime);
	}
	
	private void setNextShock(Date date) {
		
	}
}
